import {onMounted, onUnmounted, ref} from "vue";

//用户点击页面，收集x,y坐标并做展示
export const mousePosition = () => {
    const x = ref(0)
    const y = ref(0)
    const handleClick = (e: MouseEvent) => {
        x.value = e.pageX;
        y.value = e.pageY
    }
    onMounted(() => {
        window.addEventListener('click', handleClick)
    })
    onUnmounted(() => {
        window.removeEventListener('click', handleClick)
    })
    return {
        x, y
    }
}